//
//  AppDelegate.m
//  SMTools
//
//  Created by fengsh on 2018/12/24.
//  Copyright © 2018年 fengsh. All rights reserved.
//

#import "AppDelegate.h"
#import "LuckyMainVC.h"
#import <MagicalRecord/MagicalRecord.h>

@interface AppDelegate ()

@property (weak) IBOutlet NSWindow *window;
@property (strong) LuckyMainVC                      *vc;

@end

@implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    NSLog(@"%@",NSTemporaryDirectory());
    [MagicalRecord setLoggingLevel:MagicalRecordLoggingLevelWarn];
//    [MagicalRecord setupAutoMigratingCoreDataStack];
    NSString *path = [NSHomeDirectory()stringByAppendingPathComponent:@"Doucuments"];
    path = [path stringByAppendingPathComponent:@"tooldb.sqlite"];
    NSURL *dburl = [NSURL fileURLWithPath:path];
    
    [MagicalRecord setupCoreDataStackWithAutoMigratingSqliteStoreAtURL:dburl];
    
    // Insert code here to initialize your application
    [self.window setContentSize:NSMakeSize(1280, 768)];
    [self.window setMinSize:NSMakeSize(1280, 768)];
    self.vc = [[LuckyMainVC alloc]init];
    self.window.contentViewController = self.vc;
}


- (void)applicationWillTerminate:(NSNotification *)aNotification
{
    // Insert code here to tear down your application
}

- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
{
    return NO;
}

- (BOOL)applicationShouldHandleReopen:(NSApplication *)sender hasVisibleWindows:(BOOL)flag
{
    if (flag) {
        return NO;
    }
    else {
        NSWindow *mainwnd  =  sender.windows[0];
        [mainwnd makeKeyAndOrderFront:self];
        return YES;
    }
}

@end
